package com.isoft.controller.flightUpdate;

import com.isoft.bean.ResponseData;
import com.isoft.entity.flightUpdate.FlightUpdateVo;
import com.isoft.service.flightUpdate.FlightVoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author LiuGaoMing
 * @version 1.0
 * @description:
 * @date 2024/7/1 10:47
 */
@RestController
@RequestMapping("/flightHistory")
@CrossOrigin
public class FlightVoController {
    @Autowired
    private FlightVoService flightVoService;


//    分页查询所有
    @GetMapping("/getAll")
    public ResponseData<List<FlightUpdateVo>> getFlightAllVoPaged(
            @RequestParam(defaultValue = "1") int currentPage,
            @RequestParam(defaultValue = "10") int pageSize) {
        List<FlightUpdateVo> data = flightVoService.getFlightAllVoPaged(currentPage, pageSize);
        Long total = flightVoService.getTotalFlightRecords();
        return ResponseData.success(data, total);
    }
    // 模糊查询并且分页
    @GetMapping("/find")
    public ResponseData<List<FlightUpdateVo>> searchFlights(
            @RequestParam(defaultValue = "") String NAPCD1,
            @RequestParam(defaultValue = "") String NAPCD2,
            @RequestParam(defaultValue = "") String NAPCD3,
            @RequestParam(defaultValue = "1") int currentPage,
            @RequestParam(defaultValue = "10") int pageSize) {
        List<FlightUpdateVo> data = flightVoService.getFlightVoByNAPCDsPaged(NAPCD1, NAPCD2, NAPCD3, currentPage, pageSize);
        Long total = flightVoService.getTotalFlightRecordsByNAPCDs(NAPCD1, NAPCD2, NAPCD3);
        return ResponseData.success(data, total);
    }
}
